home *** CD-ROM | disk | FTP | other *** search
- // the implementation of netlist-related functions
- // Copyright (C) 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
-
- #include <list>
- #include <vector>
- #include <string.h>
- #include "../finfo.h"
- #include "nitable.h"
-
- #include "netlist.h"
-
- void NETLIST_ERROR::not_distinct(const char* comp_name)
- {
- }
-
- class NET_ELEMENT {
- std::string m_designator;
- uint m_pin_number;
- public:
- NET_ELEMENT() {}
- NET_ELEMENT(const char* designator, uint pin_number)
- : m_designator(designator),
- m_pin_number(pin_number) {}
- NET_ELEMENT(const NET_ELEMENT& elem)
- : m_designator(elem.m_designator),
- m_pin_number(elem.m_pin_number) {}
-
- const NET_ELEMENT& operator=(const NET_ELEMENT& rval) {
- m_designator = rval.m_designator;
- m_pin_number = rval.m_pin_number;
- return *this;
- }
- bool operator==(const NET_ELEMENT& rval) const; // illegal (undefined)
- bool operator!=(const NET_ELEMENT& rval) const; // illegal (undefined)
- bool operator<(const NET_ELEMENT& rval) const; // illegal (undefined)
- bool operator>(const NET_ELEMENT& rval) const; // illegal (undefined)
-
- const char* designator() const { return m_designator.c_str(); }
- uint pin_number() const { return m_pin_number; }
- };
-
- class NET_ELEMENT_LIST : public std::list<NET_ELEMENT> {
- public:
- void GetParticularNet(int net, const KBAN_DATA& kban_data) {
- const COMPONENT_LIST& component_list = kban_data.component_list();
- COMPONENT_LIST::iterator i;
- TRAVERSE(component_list, i) {
- const COMPONENT_ELEMENT& component_element = *i;
- for(uint j = 0; j < LAYER_NUMBER; j++) {
- const LAYER& layer = component_element.layer(j);
- const PIN_LIST& pin_list = layer.pin_list();
- PIN_LIST::iterator k;
- TRAVERSE(pin_list, k) {
- const PIN_ELEMENT& pin_element = *k;
- if(pin_element.net_number() == net) {
- NET_ELEMENT elem(component_element.designator(), pin_element.number());
- push_back(elem);
- }
- }
- }
- }
- }
- };
-
- bool are_distinct_component_names(NETLIST_ERROR& ne, const KBAN_DATA& kban_data)
- {
- const COMPONENT_LIST& comp_list = kban_data.component_list();
- uint size = comp_list.size();
-
- COMPONENT_LIST::iterator i;
- uint j = 0;
- std::vector<const char *> designator_table(size);
- TRAVERSE(comp_list, i) {
- designator_table[j] = i->designator();
- j++;
- }
-
- bool bDistinct = true;
- for(uint k = 0; k < size; k++) {
- for(uint l = 0; l < k; l++) {
- if(!strcmp(designator_table[k], designator_table[l])) {
- ne.not_distinct(designator_table[k]);
- bDistinct = false;
- }
- }
- }
-
- return bDistinct;
- }
-
- void output_netlist(NETLIST_ERROR& ne, const char* fname, KBAN_DATA& kban_data)
- {
- FILE_NEW fp(fname, "w");
-
- #if 0
- if(!are_distinct_component_names(ne, kban_data)) {
- fp.printf("Not Distinct\n");
- }
- #endif
-
- NET_ITEM_TABLE net_item_table;
- net_item_table.AddItem(kban_data);
- net_item_table.ResetAllConnections();
- net_item_table.GenerateNetlist(LAYER_PATTERN_TOP );
- net_item_table.GenerateNetlist(LAYER_PATTERN_BOTTOM);
- net_item_table.SetFinalNumber();
-
- for(uint i = 0, j = 1; i < net_item_table.size(); i++) {
- if(net_item_table.IsRoot(i)) {
- NET_ELEMENT_LIST net_elem_list;
- net_elem_list.GetParticularNet(i, kban_data);
- if(net_elem_list.size() != 0) {
- fp.printf("net number %3d :\n", j);
- NET_ELEMENT_LIST::iterator k;
- for(k = net_elem_list.begin(); k != net_elem_list.end(); k++) {
- const NET_ELEMENT& current_elem = *k;
- fp.printf(" %5s %3d\n",
- current_elem.designator(),
- current_elem.pin_number()
- );
- }
- j++;
- }
- }
- }
- }
-